package demo1;

/**
 * 玩家类
 */
public class Player {
    private String name;
    private int blood = 100;
    private Gun gun;
    public int getBlood() {
        return blood;
    }
    public String getName() {
        return name;
    }
    public Player(){}
    public Player(String name){
        this(name,100);
    }
    public Player(String name,int blood){
        this.name = name;
        this.blood = blood;
    }

    /**
     * 持枪
     * @param gun
     */
    public void holdGun(Gun gun){
        this.gun = gun;
    }
    /**
     * 射击
     * @param enemy 对手
     */
    public void shootEnemy(Player enemy){
        System.out.printf("%s向%s开了一枪\n",this.name,enemy.name);
        if(gun == null){
            System.out.println(">>>"+name+"没有枪,无法进行射击!");
            return;
        }
        gun.shootEnemy(enemy);
    }

    /**
     * 装弹夹
     * @param clip
     */
    public void loadClip(Clip clip){
        if(gun == null){
            System.out.println(">>>"+name+"没有枪,无法装弹夹!");
            return;
        }
        gun.loadClip(clip);
    }
    //计算损失
    public void damage(int hurt){
        if(blood == 0){
            System.out.println(">>>"+name+"已死亡,请勿鞭尸!");
            return;
        }
        blood-=hurt;
        if(blood<=0){
            blood = 0;
            System.out.println(">>>"+name+"已经死亡!");
        }
       // showPlayer();
    }
    public void showPlayer(){
        boolean isHoldGun = gun!=null;
        System.out.printf(">>>玩家信息: 姓名=%s,血量=%d,是否持枪=%b\n",name,blood,isHoldGun);
    }
}
